#region File Header
//
// MatrixD.cs - Matrix double
//
// Copyright (C) Javier Valcarce. BSD License
#endregion


#region Using Statements
using System;
#endregion


namespace Dsp
{
    
    /// <summary>
    /// Matrix, double
    /// </summary>
    public class MatrixD : ICloneable
    {
		double[]   block;
        int        data;
        int        tda;
        //
        public int Rows {get; private set; }
        public int Cols {get; private set; }

        // the CLI garbage collector takes account of this...
        //private bool owner; 
        #region Exceptions
        public class FormatException : Exception { }
        #endregion

        #region Constructors
        public MatrixD(int rows, int cols)
        {
            this.Rows = rows;
            this.Cols = cols;

            tda = cols;
            block = new double[rows * cols];
            data  = 0;
        }

        public MatrixD(double[] a, int size1, int size2)
        {
            if (a.Length != size1 * size2)
                throw new FormatException();

            this.Rows = size1;
            this.Cols = size2;

            tda   = size2;
            block = a;
            data  = 0;
        }

        #endregion

        #region Properties
        public double this[int i, int j]
        {
            get { return block[data + i * tda + j];  }
            set { block[data + i * tda + j] = value; }
        }

        /// <summary>
        /// Underliying array block
        /// </summary>
        public double[] Array
        {
            get { return block; }
            set { block = value; }
        }
        #endregion

        #region Miembros de ICloneable

        public object Clone()
        {
            throw new Exception("The method or operation is not implemented.");
        }

        #endregion
    }
}